import variables from '@/assets/styles/element-variables.scss'
import defaultSettings from '@/settings'

const { title, encryption, tagsView, fixedHeader, sidebarLogo, uniqueOpened, showLoginFooter, showFooter, footerTxt, caseNumber, technicalSupport } = defaultSettings
//获取本地缓存的设置的值
const getLocal = (key, bool) => {
  return (localStorage.getItem('set-' + key) == null || localStorage.getItem('set-' + key) == undefined) ? bool : (localStorage.getItem('set-' + key) == 'false' ? false : true)
}
const state = {
  theme: variables.theme,
  encryption: encryption,
  title: title,
  showSettings: false,
  tagsView: getLocal('tagsView', tagsView),
  fixedHeader: getLocal('fixedHeader', fixedHeader),
  sidebarLogo: getLocal('sidebarLogo', sidebarLogo),
  uniqueOpened: getLocal('uniqueOpened', uniqueOpened),
  showFooter: getLocal('showFooter', showFooter),
  showLoginFooter: showLoginFooter,
  footerTxt: footerTxt,
  caseNumber: caseNumber,
  technicalSupport: technicalSupport
}
const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value;
      localStorage.setItem('set-' + key, value);
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}



export default {
  namespaced: true,
  state,
  mutations,
  actions
}

